package Form;
import data.ManagerDatabase;
import data.Row;
import data.Table;
import java.awt.Frame;
import java.io.File;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;

public class OpenData extends JFrame {
  public OpenData() {
      
      
    
  }
  public File getNameDatabase()
  {
      JFileChooser chooser = new JFileChooser();
      chooser.setCurrentDirectory(new File("."));
      chooser.setFileFilter(new FileFilter() {
        public boolean accept(File f) {
          return f.getName().toUpperCase().endsWith(".JSQL")
              || f.isDirectory();
        }

        public String getDescription() {
          return "JSQL Files";
        }
      });
      int r = chooser.showOpenDialog(this);
      if (r == JFileChooser.APPROVE_OPTION) {
        File zipname = chooser.getSelectedFile().getAbsoluteFile();
        return zipname;
      }
        return null;

    }

    public ManagerDatabase getDataBase() {
        File namedat = getNameDatabase();
        if (namedat == null) {
            return null;
        }
        StringBuilder namefix = new StringBuilder(namedat.getName());
        namefix.delete(namefix.length() - 5, namefix.length());
        ManagerDatabase data = new ManagerDatabase(namefix.toString());
        if (data.loadAllTable(namedat.getAbsolutePath())) {
            return data;
        }
        return null;

    }
}